package com.dongdongshop.controller;

import com.dongdongshop.pojo.TbItem;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.ItemService;
import com.dongdongsop.data.AjaxResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("item")
public class ItemController {

    @DubboReference
    private ItemService itemService;

    @RequestMapping("addItem")
    @ResponseBody
    public AjaxResult addItem(TbItem item){
        try {
            Subject subject = SecurityUtils.getSubject();
            TbSeller seller = (TbSeller) subject.getPrincipal();
            item.setSellerId(seller.getSellerId());
            item.setSeller(seller.getName());
            int i = itemService.addItem(item);
            return AjaxResult.OK().setData(i);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.ERROR();
        }
    }
}
